package com.umbacos.udm.client.view;

import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.umbacos.udm.client.arch.ImageButton;
import com.umbacos.udm.client.arch.Table;
import com.umbacos.udm.client.model.View;

public class FileListView extends View {

	public final Table ftFiles = new Table();

	public final ImageButton ibRefr = new ImageButton("images/refresh2.png", 100, 24, 32);
	public final ImageButton ibTree = new ImageButton("images/tree.png", 100, 24, 32);
	public final ImageButton ibNew = new ImageButton("images/new.png", 100, 24, 32);
	public final ImageButton ibUpl = new ImageButton("images/up.png", 100, 24, 32);
	public final ImageButton ibDisk = new ImageButton("images/disk.png", 100, 24, 32);
	
	public final ListBox lbFreq = new ListBox();

	public Table getFtFiles() {
		return ftFiles;
	}

	public Label curDir;

	public FileListView() {

		RootLayoutPanel rlp=RootLayoutPanel.get();

		Image fileLogo = new Image("images/downd.png");
		fileLogo.addStyleName("valignmiddle");

		Label fileTitle = new Label("File Manager");
		fileTitle.setStyleName("viewtitle");

		lbFreq.addItem("Manual", "-1");
		lbFreq.addItem("1 sec", "1000");
		lbFreq.addItem("5 sec", "5000");
		lbFreq.addItem("10 sec", "10000");
		lbFreq.addItem("1 min", "60000");
		lbFreq.setSelectedIndex(0);
		lbFreq.setTitle("Refresh the list");

		curDir = new Label("Current Directory: /");

		Image spacer = new Image("images/transparent.gif");
		spacer.setHeight("42px");

		ibRefr.setTitle("Refresh");
		ibTree.setTitle("Open the Directory tree view");
		ibNew.setTitle("Create a new Directory");
		ibUpl.setTitle("Upload a file");
		ibDisk.setTitle("View disk info");

		HorizontalPanel toolBar=new HorizontalPanel();
		toolBar.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
		toolBar.setSpacing(5);
		toolBar.add(ibUpl);
		toolBar.add(ibDisk);
		toolBar.add(ibTree);
		toolBar.add(ibNew);
		toolBar.add(ibRefr);
		
		Grid grTitle = new Grid(1, 6);
		setTitle(grTitle);
		grTitle.setWidth(rlp.getOffsetWidth() - 200 + "px");
		grTitle.getRowFormatter().setVerticalAlign(0, HasVerticalAlignment.ALIGN_MIDDLE);
		grTitle.getCellFormatter().setHorizontalAlignment(0, 3, HasHorizontalAlignment.ALIGN_CENTER);
		grTitle.getCellFormatter().setHorizontalAlignment(0, 4, HasHorizontalAlignment.ALIGN_RIGHT);
		grTitle.getCellFormatter().setWidth(0, 0, "24px");
		grTitle.getCellFormatter().setWidth(0, 1, "200px");
		grTitle.getCellFormatter().setWidth(0, 3, "100px");
		grTitle.getCellFormatter().setWidth(0, 4, "75px");
		grTitle.getCellFormatter().setWidth(0, 5, "1px");

		grTitle.setWidget(0, 0, fileLogo);
		grTitle.setWidget(0, 1, fileTitle);
		grTitle.setWidget(0, 2, curDir);
		grTitle.setWidget(0, 3, toolBar);
		grTitle.setWidget(0, 4, lbFreq);
		grTitle.setWidget(0, 5, spacer);

		setContent(ftFiles);
		ftFiles.setCellSpacing(0);
		ftFiles.setCellPadding(0);
		ftFiles.addStyleName("arrow");
		ftFiles.resize(1, 4);
		ftFiles.getColumnFormatter().setWidth(0, "150px");
		ftFiles.getColumnFormatter().setWidth(1, "75px");
		ftFiles.getColumnFormatter().setWidth(2, "40px");
		ftFiles.getColumnFormatter().setWidth(3, ftFiles.getParent().getOffsetWidth() - 265 + "px");

		Grid fhFiles=new Grid(1,4);
		setHeader(fhFiles);
		fhFiles.setWidth(rlp.getOffsetWidth() - 315 + "px");
		fhFiles.setCellSpacing(0);
		fhFiles.setCellPadding(0);
		fhFiles.getColumnFormatter().setWidth(0, "150px");
		fhFiles.getColumnFormatter().setWidth(1, "75px");
		fhFiles.getColumnFormatter().setWidth(2, "40px");
		fhFiles.getCellFormatter().setAlignment(0, 0, HasHorizontalAlignment.ALIGN_RIGHT, HasVerticalAlignment.ALIGN_MIDDLE);
		fhFiles.getCellFormatter().setAlignment(0, 1, HasHorizontalAlignment.ALIGN_RIGHT, HasVerticalAlignment.ALIGN_MIDDLE);
		fhFiles.getCellFormatter().setAlignment(0, 2, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE);
		fhFiles.getCellFormatter().setAlignment(0, 3, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_MIDDLE);
		fhFiles.getRowFormatter().setStyleName(0, "header");
		fhFiles.setText(0, 0, "Date");
		fhFiles.setText(0, 1, "Size");
		fhFiles.setText(0, 3, "Name");
	}

}
